"""#urlencode应用场景:url中存在多个参数
import urllib.request
import urllib.parse

#https://www.baidu.com/s?wd=侯国玉&sex=电棍

#将参数以字典的形式存储
data = {"wd":"侯国玉","sex":"电棍"}

para =urllib.parse.urlencode(data)

获取https://www.baidu.com/s?wd=%E4%BE%AF%E5%9B%BD%E7%8E%89&sex=%E7%94%B5%E6%A3%8D源码"""
import urllib.request
import urllib.parse

data = {"wd":"侯国玉","sex":"电棍"}
para = urllib.parse.urlencode(data)

url = "https://www.baidu.com/s?"
url = url+para
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0'}
request = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode("utf-8")

print(content)
